package com.godz.controller.index3;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.*;
import com.godz.pojo.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author GodzIINeo2023
 */
@Controller
public class index3Controller {
    /* 我的梦想 */
    final
    index3DreamMapper dreamMapper;
    final
    index3MindMapper mindMapper;//身边人的思想
    final
    index3WorkExpMapper workExpMapper;//工作经历
    final
    index3EduExpMapper eduExpMapper;//教育经历
    final
    eduPrimMapper eduPrimMapper;//教育经历详细内容

    public index3Controller(
            index3DreamMapper dreamMapper,
            index3MindMapper mindMapper,
            index3WorkExpMapper workExpMapper,
            index3EduExpMapper eduExpMapper,
            eduPrimMapper eduPrimMapper
    ) {
        this.dreamMapper = dreamMapper;
        this.mindMapper = mindMapper;
        this.workExpMapper = workExpMapper;
        this.eduExpMapper = eduExpMapper;
        this.eduPrimMapper = eduPrimMapper;
    }
    /**
     * 个人信息详情页,比较重要
     */
    @RequestMapping("/index3")
    public String index3(Model model){
        List<index3Dream> dreams = dreamMapper.queryAllDream();
        model.addAttribute("dreams",dreams);

        List<index3Mind> minds = mindMapper.queryAllMind();
        model.addAttribute("minds",minds);

        List<index3WorkExp> workExps = workExpMapper.queryAllWork();
        model.addAttribute("works",workExps);
        //1对多进行查询单条数据,教育时期照片
        List<index3EduExp> eduExps = eduExpMapper.queryAllEduExp();
        for (index3EduExp eduExp : eduExps) {
            QueryWrapper<eduPrim> wrapper = new QueryWrapper<eduPrim>()
                    .eq("ee_linkid", eduExp.getEeLinkid())//1对多,连接连接id
                    .orderByAsc("prim_start")//倒序排序
                    .last("limit 1");
            eduPrim prim = eduPrimMapper.selectOne(wrapper);//查询故事的一个图片
            eduExp.setImg(prim.getPrimImg());
        }
        model.addAttribute("eduExps",eduExps);

        return "index3";
    }
}
